from flask import Flask, render_template
from blueprints.home import home_bp
from blueprints.admin import admin_bp
from blueprints.auth import auth_bp
from models import db

app = Flask(__name__)
app.secret_key = 'your-secret-key-here'
app.config['SESSION_TYPE'] = 'filesystem'

# 数据库配置
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost:4000/mini_blog'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# 初始化SQLAlchemy
db.init_app(app)

# 注册蓝图
app.register_blueprint(home_bp)
app.register_blueprint(admin_bp, url_prefix='/admin')
app.register_blueprint(auth_bp)

# 错误处理
@app.errorhandler(404)
def page_not_found(e):
    return render_template('shared/404.html'), 404

@app.errorhandler(500)
def internal_server_error(e):
    return render_template('shared/500.html'), 500

if __name__ == '__main__':
    app.run(debug=True)